package cn.edu.zut.internship.web.controller.sys;

import cn.edu.zut.internship.bean.sys.Result;
import cn.edu.zut.internship.entity.AuthSysMenu;
import cn.edu.zut.internship.iservice.sys.IAuthService;
import cn.edu.zut.internship.iservice.sys.IMenuService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/menu")

public class MenuController {
    @Reference
    private IAuthService authService;
    @Reference
    private IMenuService menuService;
    @GetMapping("/search/tree")
    public Result searchMenuTree(){
        Result result = new Result();
        List<AuthSysMenu> menuList = this.authService.getMenus();
        result.setBeans(menuList);
        return result;
    }
    @PostMapping("/create")
    public Result addMenu(@RequestBody AuthSysMenu menu){
        Result result = new Result();
        this.menuService.addMenu(menu);
        return result;
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteMenu(@PathVariable("id") Long id){
        Result result = new Result();
        this.menuService.deleteMenu(id);
        return result;
    }

    @RequestMapping("/update")
    public Result editMenu(@RequestBody AuthSysMenu menu){
        Result result = new Result();
        this.menuService.editMenu(menu);
        return result;
    }
}
